package com.example.demo.demos.web.controller;

import com.example.demo.demos.web.entity.Zl;
import com.example.demo.demos.web.mapper.CarMapper;
import com.example.demo.demos.web.mapper.ZlMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("index")
public class ZlController {
    @Autowired
    private ZlMapper zlMapper;
    @Autowired
    private CarMapper carMapper;

    @PostMapping("/zlddadd")
    public Map<String,Object> add(@RequestBody Zl zl){
        Map<String,Object> res=new HashMap<>();
        Integer isadd=zlMapper.addzl(zl);
        if(isadd == 1){
            res.put("code",200);
            res.put("msg","提交成功");

        }else{
            res.put("code",500);
            res.put("msg","提交失败");

        }
        return  res;

    }
    @GetMapping("/zllist")
    public Map<String,Object> index(@RequestParam Integer pageNum,@RequestParam Integer pageSize){
        Map<String,Object> res=new HashMap<>();
        pageNum=(pageNum-1)*pageSize;
        List<Zl> data=zlMapper.selectzl(pageNum,pageSize);
        Integer total=zlMapper.selectnum();
        res.put("code",200);
        res.put("data",data);
res.put("total",total);
        return  res;
    }
    @GetMapping("/grzl")
    public Map<String,Object> index(@RequestParam String uid){
        Map<String,Object> res=new HashMap<>();

        List<Zl> data=zlMapper.selectzluser(uid);

        res.put("code",200);
        res.put("data",data);

        return  res;
    }
    @PostMapping("/sh")
    public Map<String,Object> sh(@RequestBody Zl zl){
        Map<String,Object> res=new HashMap<>();
     Integer issh=zlMapper.update(zl);
        System.out.println("321");
     System.out.println(zl.getStatus());
        System.out.println("123");

      if(zl.getStatus().equals("1")){
          System.out.println("这里");
          Integer isxg=carMapper.updatestatus(zl.getCarid());
          if(isxg == 1 && issh == 1){
              res.put("code",200);
              res.put("msg","审核成功");
          }
      }else {
          System.out.println("那里");
          if(issh == 1){
              res.put("code",200);
              res.put("msg","审核成功1");
          }
      }
        return res;
    }
    @PostMapping("gh")
    public Map<String,Object> gh(@RequestBody Zl zl){
        Map<String,Object> res=new HashMap<>();
        Integer issh=zlMapper.update(zl);
        System.out.println("321");
        System.out.println(zl.getStatus());
        System.out.println("123");

        if(zl.getStatus().equals("3")){
            System.out.println("这里");
            Integer isxg=carMapper.updatestatus1(zl.getCarid());
            if(isxg == 1 && issh == 1){
                res.put("code",200);
                res.put("msg","归还成功");
            }
        }
        return res;
    }
    @GetMapping("/grgh")
    public Map<String,Object> index1(@RequestParam String uid){
        Map<String,Object> res=new HashMap<>();

        List<Zl> data=zlMapper.selectzluser1(uid);

        res.put("code",200);
        res.put("data",data);

        return  res;
    }

}
